var express = require('express');// 引入express模块
var app = express();
const fs = require('fs');
const querystring = require('querystring');
const bodyParser = require('body-parser');
const cors = require('cors');
app.use(cors());
app.use(bodyParser.urlencoded({ extended: false }));

// 响应接口
app.post('/index', (req, res, next) => {
    let data = '';
    req.on('data', function (chunk) {
        data += chunk;
    });
    req.on('end', function () {
        let dataDemo = querystring.parse(data).data;
        fs.writeFileSync('../src/demoData/demotest.txt', JSON.parse(JSON.stringify(dataDemo)));
        res.send('完成');
        next();
    });

    // const data = req.body
    // res.send(data)
});
app.post('/getjson', (req, res, next) => {
    let data = fs.readFileSync('../src/demoData/demotest.txt');
    // const data = req.body
    res.send(data.toString());
    next();
});
// 定义端口，此处所用为3000端口，可自行更改
app.listen(3070, function () {
    console.log('runing 3000...');
});
